<template>
  <div class="index-page">
    <!-- 轮播图 -->
    <van-swipe class="my-swipe" :autoplay="3000" indicator-color="white">
      <van-swipe-item
      v-for="(item,index) in pic"
      :key="index"
      ><img :src="item" alt="">
      </van-swipe-item>
    </van-swipe>
    <!-- 搜索 -->
      <div class="van-search">
        <router-link
        class="btn" to="/cityList">{{city}}
        </router-link>
        <input class="ipt" type="text" placeholder="请输入校区或地址">
      <van-icon name="location-o" size="25" @click="$router.push('/mapFind')"/>
      </div>
      <div class="div">
        <van-icon name="https://img1.baidu.com/it/u=2744299766,2384149717&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=500"/>
      </div>
      <!-- 导航 -->
      <div class="nav" @click="$router.push('/find')">
        <div class="box">
          <div class="top"><img src="" alt=""></div>
          <div class="bottom">整租</div>
        </div>
        <div class="box" @click="$router.push('/find')">
          <div class="top"><img src="" alt=""></div>
          <div class="bottom">合租</div>
        </div>
        <div class="box" @click="$router.push('/mapFind')">
          <div class="top"><img src="" alt=""></div>
          <div class="bottom">地图找房</div>
        </div>
        <div class="box" @click="$router.push('/pushHouse')">
          <div class="top"><img src="" alt=""></div>
          <div class="bottom">去出租</div>
        </div>
      </div>
      <!-- 租房小组 -->
      <div class="small">
        <div class="title">
        <div class="left"> <h3>租房小组</h3> </div>
        <div class="more">更多</div>
      </div>
      <div class="item">
        <div class="box" v-for="item in group" :key="item.id">
          <div class="left"><img class="img" :src="item.imgSrc" alt=""></div>
          <div class="right">{{item.title}} {{item.desc}} </div>
        </div>
      </div>
      </div>
  </div>
</template>

<script>
import { homePic, groups } from '@/api/home'
import { getCityName } from '@/utils/storage'
export default {
  name: 'index-page',
  data () {
    return {
      city: getCityName() ? getCityName() : '上海',
      pic: [],
      value: '',
      group: []
    }
  },
  async created () {
    // 轮播图
    const res = await homePic()
    // console.log(res)
    this.pic = res.body.map(item => {
      return `http://121.199.51.160:8080${item.imgSrc}`
    })
    // 租房小组导航样式
    const reslut = await groups()
    // console.log(reslut)
    reslut.body.forEach(item => {
      item.imgSrc = `http://121.199.51.160:8080${item.imgSrc}`
    })
    this.group = reslut.body
  },
  methods: {

  }
}
</script>

<style lang="less" scoped>
.index-page {
  margin-bottom: 50px;
  position: relative;
  .div{
    width: 16px;
    height: 16px;
    position: absolute;
    transform: translate(60px,-180px);
  }
  .my-swipe .van-swipe-item {
    color: #fff;
    font-size: 20px;
    height: 212px;
    line-height: 150px;
    text-align: center;
    background-color: #39a9ed;
    img{
      width: 100%;
    }
  }
  .van-search{
    position: relative;
    margin-left: 15px;
    padding: 0;
    width: 315px;
    height: 34px;
    border-radius: 3px;
    position: absolute;
    transform: translateY(-190px);
    .van-icon{
    position: absolute;
    transform: translate(325px);
  }
    .btn{
      height: 70%;
      font-size: 14px;
      width: 60px;
      line-height: 25px;
      padding-left: 10px;
      border-radius: 3px;
      color:#333;
      background-color: #f6f6f6;
      border: 1px solid #fff;
    }
    .ipt{
      margin-left: 10px;
      height: 85%;
      border: 1px solid #f6f6f6;
      font-size: 12px;
      color: #999999;
    }
  }
  .nav{
    margin-top: 15px;
    display: flex;
    width: 100%;
    height: 88px;
    text-align: center;
    .top{
      width: 95px;
      height: 89px;
      img{
        width: 60px;
      }
    }
    .bottom{
      font-size: 13px;
      color: #333;
      transform: translateY(-15px);
    }
  }
  .small{
    background-color: #f6f5f6;
    height: 200px;
    .title{
    display: flex;
    align-items: center;
    position: relative;
    margin: 15px 0 15px 10px;
    font-size: 15px;
    .left{
      font-size: 12px;
      font-weight: 700;
    }
    .more{
      font-size: 14px;
      color: #999;
      transform: translateX(270px);
    }
  }
  .item{
    display: flex;
    flex-wrap: wrap;
    transform: translateX(3px);
    transform: translateY(-26px);
    .box{
      display: flex;
      padding-right: 30px;
      margin: 7px;
      width: 172px;
      height: 60px;
      border-radius: 4px;
      box-sizing: border-box;
      background-color: white;
      .left{
        width: 50px;
        height: 50px;
        margin-top: 5px;
        margin-left: 5px;
        background-color: skyblue;
        .img{
          width: 50px;
          height: 50px;
        }
      }
      .right{
        padding-top: 10px;
        font-size: 14px;
        color: #333;
        transform: translateX(14px);
      }
    }
  }
  }

}
</style>
